package LeetCode.leetcode232;

import java.util.Stack;

public class Review1 {
    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public Review1() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        int res = 0;
        int tmp;
        while (!stack1.isEmpty()){
            tmp = stack1.pop();
            if (stack1.isEmpty()){
                res = tmp;
            }else {
                stack2.push(tmp);
            }
        }
        while (!stack2.isEmpty()){
            stack1.push(stack2.pop());
        }
        return res;
    }

    public int peek() {
        int res = 0;
        int tmp;
        while (!stack1.isEmpty()){
            tmp = stack1.pop();
            if (stack1.isEmpty()){
                res = tmp;
            }
            stack2.push(tmp);
        }
        while (!stack2.isEmpty()){
            stack1.push(stack2.pop());
        }
        return res;
    }

    public boolean empty() {
        return stack1.isEmpty();
    }
}
